<template>
	<u-popup :show="show" mode="center" :safe-area-inset-bottom="false" :customStyle="{'width': '80%'}" round="16rpx">
		<view class="c-modal">
			<view class="head">{{title}}</view>
			<view class="content">
				<slot></slot>
			</view>
			<view class="footer">
				<view class="cancel-btn" v-if="showCancel" @click="cancel">取消</view>
				<view class="confirm-btn" @click="confirm">{{confirmText}}</view>
			</view>
		</view>
	</u-popup>
</template>

<script>
	export default {
		name: "c-modal",
		props: {
			value: {
				type: Boolean,
				default: true
			},
			title: {
				type: String,
				default: '提示'
			},
			showCancel: {
				type: Boolean,
				default: true
			},
			confirmText: {
				type: String,
				default: '确认'
			}
		},
		data() {
			return {

			};
		},
		computed: {
			show: {
				get() {
					return this.value
				},
				set(val) {
					this.$emit('input', val)
				}
			}
		},
		methods: {
			cancel() {
				this.show = false
			},
			confirm() {
				this.$emit('confirm')
			}
		}
	}
</script>

<style lang="scss" scoped>
	.c-modal {
		.head {
			text-align: center;
			font-size: 34rpx;
			padding-top: 36rpx;
		}

		.content {
			padding: 22rpx;
			margin: 32rpx 0;
		}

		.footer {
			display: flex;
			justify-content: center;
			text-align: center;
			border-top: 1rpx solid #E5E5E5;
			margin: 0;
			view {
				height: 96rpx;
				line-height: 96rpx;
				text-align: center;
				flex: 1;

				&.cancel-btn {
					border-right: 1rpx solid #E5E5E5;
					color: $-color-muted;
				}
				&.confirm-btn {
					color: #000;
				}
			}
		}
	}
</style>
